﻿Namespace Catalog
    Public Class Artist
        Inherits BaseObject
        Public Property LastPublishDate As Date
        Public Property Biography As String
        Public Property Genres As List(Of Genre)
        Public Property Images As List(Of Image)

        Public Sub New()
            Me.Genres = New List(Of Genre)
            Me.Images = New List(Of Image)
        End Sub

        Public Shared Function FromBPObject(art As BPOArtist) As Artist
            If art Is Nothing Then Return Nothing
            Dim newArtist As New Artist()

            newArtist.ID = art.id
            newArtist.Name = art.name
            newArtist.Slug = art.slug
            Date.TryParseExact(art.lastPublishDate, "yyyy-MM-dd", Nothing, Globalization.DateTimeStyles.None, newArtist.LastPublishDate)
            newArtist.Biography = art.biography

            If art.genres IsNot Nothing Then
                For Each g As BPOGenreBase In art.genres
                    Dim newGenre As New Genre()
                    newGenre.ID = g.id
                    newGenre.Name = g.name
                    newGenre.Slug = g.slug
                    newArtist.Genres.Add(newGenre)
                Next
            End If

            If art.images IsNot Nothing Then
                For Each img As KeyValuePair(Of String, BPOImage) In art.images
                    Dim newImage As Image = Image.FromBPObject(img)
                    newArtist.Images.Add(newImage)
                Next
            End If

            Return newArtist
        End Function
    End Class
End Namespace